<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>路由访问页面</title>
</head>
<body>
<h3>路由访问页面</h3>
<p><input type="button" value="AJAX异步请求，无登录判断" onclick="ajaxTestWithoutAuthState();"></p>
<p><input type="button" value="AJAX异步请求，登录状态判断" onclick="ajaxTestWithAuthState();"></p>
<% if(isNotEmpty(sessionData)){ %>
<p>${sessionData.userAlias},欢迎登录！</p><a href="${ctxPath}/logout">退出登录</a>
<% } else { %>
<p>未登录</p><a href="http://passportsit.chenlintech.com:8080/ids?service=http://samplesit.chenlintech.com:9090/sample/test/routerAcess">登录</a>
<% } %>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

    function ajaxTestWithoutAuthState() {
        $.get('${ctxPath}/test/ajaxAccess', null, function(data) {
            alert(data);
        });
    }

    function ajaxTestWithAuthState() {
        $.ajax({
            url: '${ctxPath}/authStatus',
            type: 'GET',
            dataType: 'jsonp',
            jsonpCallback: 'hasLogin'
        });
    }

    function hasLogin(data) {
        if(!data.hasLogin) {
            console.log('用户未登录，请拼接登录地址跳转！');
            window.open('http://passportsit.chenlintech.com:8080/ids/login?service=http://samplesit.chenlin.com:9090/sample/auth&targetUrl=http://samplesit.chenlin.com:9090/sample/test/routerAccess', '_self');
            return false;
        }
        $.get('${ctxPath}/test/ajaxAccess', null, function(data) {
            alert(JSON.stringify(data));
        });
    }
</script>
</html>